'use strict';
const {
  Model
} = require('sequelize');

module.exports = (sequelize, DataTypes) => {
  class New extends Model {
     // 查询分页数据
    /* async getNews(page,limit) {
         
        
     } */
     // 添加入库
     async addNews(data){
          try{
              await New.create(data)
          }catch(e){
              throw new Error(e.message)
          } 
     }


    /**
     * Helper method for defining associations.
     * This method is not a part of Sequelize lifecycle.
     * The `models/index` file will call this method automatically.
     */
    static associate(models) {
         models.New.belongsTo(models.Cate)
    }
  }
  New.init({
    title: DataTypes.STRING,
    content: DataTypes.TEXT('long'),
    img_url: DataTypes.STRING,
    cateId: DataTypes.INTEGER,
    author: DataTypes.STRING,
    add_time: DataTypes.DATE,
    view_nums: DataTypes.INTEGER,
    data_flag: DataTypes.INTEGER
  }, {
    sequelize,
    modelName: 'New',
  });
  return New;
};